home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / system / startppp.000 / startppp / Startppp_v0.80 / startppp_partial < prev    next >
Encoding:
Text File  |  1995-08-15  |  32.9 KB  |  1,013 lines

  1. #
  2. # Startppp
  3. # Copyright (C) 1995  Matthias Ott 
  4. #  (msott@cip.informatik.uni-erlangen.de)
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Library General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 2 of the License, or (at your option) any later version.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. # Library General Public License for more details.
  13. # You should have received a copy of the GNU Library General Public
  14. # License along with this program; if not, write to the Free
  15. # Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. #
  17.  
  18. set progname [file tail $argv0]
  19. set commandoption [lindex $argv 0]
  20. set version "v0.80"
  21. set instdir "/usr/local/lib/startppp"
  22. set moneyfile "$env(HOME)/.${progname}_money"
  23. set configfile "$env(HOME)/.${progname}_config"
  24. set expectfile "$env(HOME)/.${progname}_expect"
  25. set onlinetime "00:00:00";         # how long are you online
  26. set lastonlinetime "00:00:00";        # time to next unit
  27. set modemdevice /dev/modem;        # modem to use
  28. set dialtry 0;                 # how often did you dial already
  29. set Iconify 0;                 # iconify program after connection
  30. set showterminal 1;            # show terminal while dialing
  31. set startdelay 4;             # how long does it take to connect
  32. set showmoneyinicon 1;             # display time in iconname
  33. set flagwarning 0;             # time-warning yes/no
  34. set warningtime 60;             # warningperiod (min)
  35. set refreshtime 1;             # refresh-delay of onlinetime (sec)
  36. set button 1;                 # how many seconds per unit, default
  37. set zonedaytime 1;             # daytime or nighttime
  38. set realunits 60;            # display realunits
  39. set money "0.00";             # how much money does it cost 
  40. set linestatus "LINE down";         # status of connection
  41. set ppp_up "/etc/ppp/ppp-up";         # dialing-program
  42. set ppp_down "/etc/ppp/ppp-down";     # canceling-program
  43. set nightstart 18;             # start of cheapzone
  44. set nightstop 8;             # end of cheapzone
  45. set modeminit ATZ;            # Initstring for modem
  46. set dialtype T;                # T: tone, P: pulse
  47. set modemnumber 858111;            # Number to dial
  48. set repeatdelay 1;            # delay between dialing
  49. set modemspeed "38400";            # Speed of line
  50. set modemparity "CS8";            # Parity
  51. set modemstopbits "|";            # How many stopbits
  52. set modemtimeout 60;            # timeout for expect
  53. set zoneday(0) 1;             # Sunday
  54. set zoneday(1) 0;             # Monday
  55. set zoneday(2) 0;             # Tuesday
  56. set zoneday(3) 0;             # Wednesday
  57. set zoneday(4) 0;             # Thursday
  58. set zoneday(5) 0;             # Friday
  59. set zoneday(6) 1;             # Saturday
  60.  
  61. set zone(1) 360;             # Length (sec)
  62. set zone(2) 60;             # Length (sec)
  63. set zone(3) 21;             # Length (sec)
  64. set zonemoney 0.23;             # How much is one unit
  65. set currency DM;             # Currency
  66. set button 1;                 # default of zones
  67. set pid 0;                # child pid
  68.  
  69. # config-files
  70.  
  71. # common config
  72.  
  73. if {[catch {open $configfile r} Datei] == 1} {
  74.   tk_dialog .config "Config" "No file $configfile" error 0 ok
  75. } else {
  76.   gets $Datei instdir
  77.   gets $Datei zone(1)
  78.   gets $Datei zone(2)
  79.   gets $Datei zone(3)
  80.   gets $Datei zonemoney
  81.   gets $Datei currency
  82.   gets $Datei showmoneyinicon
  83.   gets $Datei Iconify
  84.   gets $Datei ppp_up
  85.   gets $Datei ppp_down
  86.   gets $Datei alterrefresh
  87.   gets $Datei button
  88.   gets $Datei alternightstart
  89.   gets $Datei alternightstop
  90.   gets $Datei flagwarning
  91.   gets $Datei warningtime
  92.   gets $Datei zoneday(0)
  93.   gets $Datei zoneday(1)
  94.   gets $Datei zoneday(2)
  95.   gets $Datei zoneday(3)
  96.   gets $Datei zoneday(4)
  97.   gets $Datei zoneday(5)
  98.   gets $Datei zoneday(6)
  99.   gets $Datei startdelay
  100.   gets $Datei modeminit
  101.   gets $Datei modemnumber
  102.   gets $Datei dialtype
  103.   gets $Datei modemdevice
  104.   gets $Datei repeatdelay
  105.   gets $Datei modemspeed
  106.   gets $Datei modemparity
  107.   gets $Datei modemstopbits
  108.   gets $Datei modemtimeout
  109.   gets $Datei showterminal
  110.   close $Datei
  111. }
  112.  
  113. if {$button!="1" && $button!="2" && $button!="3"} {
  114.   set button 1
  115.  
  116. set modemdevicetail [file tail $modemdevice]
  117. set zonelength $zone($button)
  118. if {[catch {expr int($alterrefresh)}] == 0} {
  119.   set refreshtime $alterrefresh
  120. } else {
  121.   set alterrefresh $refreshtime
  122. }
  123.  
  124. if {[catch {expr int($alternightstart)}] == 0} {
  125.   set nightstart $alternightstart
  126. } else {
  127.   set alternightstart $nightstart
  128. }
  129. if {[catch {expr int($alternightstop)}] == 0} {
  130.   set nightstop $alternightstop
  131. } else {
  132.   set alternightstop $nightstop
  133. }
  134.  
  135. # Ressource
  136. set Ressource $instdir/Startppp
  137.  
  138. if [catch {option readfile $Ressource startup} err] {
  139.   tk_dialog .config "Config" "$err: change it, but use it!!!" error 0 ok
  140. }
  141.  
  142.  
  143. # Pictures
  144.  
  145. set mypicup [image create photo -file "$instdir/eye11.ppm"]
  146. set mypicup2 [image create photo -file "$instdir/eye12.ppm"]
  147. set mypicdown [image create photo -file "$instdir/eye24.ppm"]
  148. set mypicdown2 [image create photo -file "$instdir/eye25.ppm"]
  149. set mypicexit [image create photo -file "$instdir/cancel.ppm"]
  150. set mypicpppup [image create photo -file "$instdir/pppup.ppm"]
  151. set mypicpppdown [image create photo -file "$instdir/pppdown.ppm"]
  152.  
  153.  
  154. # hints for the window-manager
  155.  
  156. tk appname $progname
  157. wm title . "$progname $version"
  158. wm iconbitmap . "@$instdir/pppdownicon"
  159. wm iconname . $progname
  160. wm protocol . WM_DELETE_WINDOW bell
  161.  
  162. #
  163. # Something like this does not work because of a bug
  164. # in the Iconbox of fvwm
  165. # maybe I can use this later on
  166. #
  167. # toplevel .icon -cursor man
  168. # label .icon.image -image $mypicdown
  169. # pack .icon.image
  170. # wm iconwindow . .icon
  171. #
  172.  
  173. # menubar
  174.  
  175. frame .mbar -relief raised -bd 2
  176.  
  177. # help-button
  178.  
  179. menubutton .mbar.help -cursor sb_down_arrow -text Help -underline 0 -menu .mbar.help.menu
  180. menu .mbar.help.menu
  181. .mbar.help.menu add command -label "About $progname $version     " -underline 0 -accelerator Ctrl+a -command {about $version}
  182. .mbar.help.menu add command -label "Help" -underline 0 -accelerator Ctrl+h -command {Help}
  183.  
  184. # options-button
  185.  
  186. menubutton .mbar.options -cursor sb_down_arrow -text Options -underline 0 -menu .mbar.options.menu
  187. menu .mbar.options.menu
  188. .mbar.options.menu add checkbutton -label "Iconify" -variable Iconify
  189. .mbar.options.menu add checkbutton -label "Onlinetime in Icon" -variable showmoneyinicon
  190. .mbar.options.menu add checkbutton -label "Show terminal" -variable showterminal
  191.  
  192. menubutton .mbar.config -cursor sb_down_arrow -text Configs -underline 0 -menu .mbar.config.menu
  193. menu .mbar.config.menu
  194. .mbar.config.menu add command -label "Show money...     " -underline 0 -accelerator Ctrl+s -command {wholemoney $moneyfile $currency} 
  195. .mbar.config.menu add separator
  196. .mbar.config.menu add command -label "Alter options...     " -underline 6 -accelerator Ctrl+o -command alterunits
  197. .mbar.config.menu add command -label "Alter modem...     " -underline 6 -accelerator Ctrl+m -command altermodem
  198. .mbar.config.menu add separator
  199. .mbar.config.menu add command -label "Change state...     " -underline 0 -accelerator Ctrl+c -command changestate
  200.  
  201.  
  202. focus .mbar
  203.  
  204. # eventbinding for the menubar
  205.  
  206. bind . <Control-a> {about $version}
  207. bind . <Control-h> {Help}
  208. bind . <Control-s> {wholemoney $moneyfile $currency}
  209. bind . <Control-o> {alterunits}
  210. bind . <Control-m> {altermodem}
  211. bind . <Control-x> {Exit $moneyfile}
  212. bind . <Control-c> {changestate}
  213.  
  214.  
  215. # buttons for the functions
  216.  
  217. frame .button
  218. button .button.up -cursor target -image $mypicpppup -command {up}
  219. button .button.down -cursor target -image $mypicpppdown -command {down}
  220. button .button.exit -cursor target -image $mypicexit -command {Exit $moneyfile}
  221.  
  222. # display information
  223.  
  224. frame .info -cursor cross -relief ridge -borderwidth 4 
  225.  
  226. # connection-data, from <ip>
  227.  
  228. frame .info.status -relief sunken -borderwidth 4   
  229. frame .info.status.unitlength
  230. label .info.status.unitlength.label -text "Length of one unit (sec):"
  231. label .info.status.unitlength.output -textvariable realunits -width 8 -anchor w
  232. frame .info.status.ifname
  233. label .info.status.ifname.label -text "Interface-name:"
  234. label .info.status.ifname.output -textvariable Ifname -width 10 -anchor w
  235. frame .info.status.ttyname
  236. label .info.status.ttyname.label -text "Device:"
  237. label .info.status.ttyname.output -textvariable Ttydev
  238. frame .info.status.pppspeed
  239. label .info.status.pppspeed.label -text "Speed:"
  240. label .info.status.pppspeed.output -textvariable Pppspeed
  241. frame .info.status.localip
  242. label .info.status.localip.label -text "Local IP:"
  243. label .info.status.localip.output -textvariable Localip
  244. frame .info.status.remoteip
  245. label .info.status.remoteip.label -text "Remote IP:"
  246. label .info.status.remoteip.output -textvariable Remoteip
  247. frame .info.status.message -relief ridge -bd 2
  248. label .info.status.message.label -text "          "
  249. label .info.status.message.output -textvariable message
  250.  
  251. # display status
  252.  
  253. frame .info.action -relief groove -borderwidth 4  
  254.  
  255. frame .info.action.ppp -relief ridge -borderwidth 3
  256. label .info.action.ppp.info -image $mypicdown
  257.  
  258. frame .info.action.time
  259. label .info.action.time.label -text "Time:    "
  260. label .info.action.time.time -textvariable Time
  261. frame .info.action.onlinetime
  262. label .info.action.onlinetime.label -text "Online:    "
  263. label .info.action.onlinetime.time -textvariable onlinetime -width 10 -anchor w
  264. frame .info.action.lastonlinetime
  265. label .info.action.lastonlinetime.label -text "Next:    "
  266. label .info.action.lastonlinetime.time -textvariable lastonlinetime -width 10 -anchor w
  267. frame .info.action.money
  268. label .info.action.money.label -text "Money:    "
  269. label .info.action.money.money -textvariable money
  270. frame .info.action.dialtry
  271. label .info.action.dialtry.label -text "Dialing:    "
  272. label .info.action.dialtry.dialtry -textvariable dialtry
  273.  
  274. bind .info.action.ppp.info <Enter> {
  275.   goodieenter
  276. }
  277. bind .info.action.ppp.info <Leave> {
  278.   goodieleave
  279. }
  280.  
  281. . configure -bg [option get .mbar.help background Background]
  282.  
  283. # the whole packing
  284.  
  285. pack .mbar -side top -fill x
  286. pack .mbar.help -side right
  287. pack .mbar.options -side left
  288. pack .mbar.config -side left
  289.  
  290. pack .button -side bottom -fill x
  291. pack .button.up -side left -padx 20 -pady 10
  292. pack .button.down -side left -padx 10 -pady 10
  293.  
  294. pack .button.exit -side right -padx 10 -pady 10
  295.  
  296. pack .info -side top -fill x -fill y -pady 5 -padx 5
  297. pack .info.status -side left -fill y -anchor w
  298. pack .info.action -side right -anchor e
  299. pack .info.status.unitlength -side top -anchor w -pady 0
  300. pack .info.status.unitlength.label -side left
  301. pack .info.status.unitlength.output -side left
  302. pack .info.status.ifname -side top -anchor w -pady 0
  303. pack .info.status.ifname.label -side left
  304. pack .info.status.ifname.output -side left
  305. pack .info.status.ttyname -side top -anchor w -pady 0
  306. pack .info.status.ttyname.label -side left
  307. pack .info.status.ttyname.output -side left
  308. pack .info.status.pppspeed -side top -anchor w -pady 0
  309. pack .info.status.pppspeed.label -side left
  310. pack .info.status.pppspeed.output -side left
  311. pack .info.status.localip -side top -anchor w -pady 0
  312. pack .info.status.localip.label -side left
  313. pack .info.status.localip.output -side left
  314. pack .info.status.remoteip -side top -anchor w -pady 0
  315. pack .info.status.remoteip.label -side left
  316. pack .info.status.remoteip.output -side left
  317. pack .info.status.message -side top -fill x -anchor w -pady 0
  318. pack .info.status.message.label -side left
  319. pack .info.status.message.output -side left -fill x
  320.  
  321. pack .info.action.ppp -side top -anchor w
  322. pack .info.action.ppp.info 
  323. pack .info.action.time -side top -anchor w
  324. pack .info.action.time.label -side left 
  325. pack .info.action.time.time -side left 
  326. pack .info.action.onlinetime -side top -anchor w
  327. pack .info.action.onlinetime.label -side left 
  328. pack .info.action.onlinetime.time -side left
  329. pack .info.action.lastonlinetime -side top -anchor w
  330. pack .info.action.lastonlinetime.label -side left 
  331. pack .info.action.lastonlinetime.time -side left
  332. pack .info.action.money -side top -anchor w
  333. pack .info.action.money.label -side left 
  334. pack .info.action.money.money -side left 
  335. pack .info.action.dialtry -side top -anchor w
  336. pack .info.action.dialtry.label -side left 
  337. pack .info.action.dialtry.dialtry -side left 
  338.  
  339.  
  340. # the functions
  341.  
  342. # dial ppp 
  343.  
  344. proc up {} {
  345.   global linestatus message showterminal pid modemdevicetail modemdevice
  346.   if {$linestatus == "LINE up"} {
  347.     set message "line already active"
  348.     return
  349.   } else {
  350.     set modemdevicetail [file tail $modemdevice]
  351.     if {$showterminal == 1} showterminal
  352.     set pid [dialproc]
  353.     set message $pid
  354.   }
  355. }
  356.  
  357.  
  358. proc up2 {} {
  359.   global ppp_up mypicup instdir
  360.   exec $ppp_up &
  361.   .info.action.ppp.info configure -image $mypicup
  362.   wm iconbitmap . "@$instdir/pppupicon"
  363. }
  364.  
  365.  
  366. # cancel ppp 
  367.  
  368. proc down {} {
  369.   global message pid ppp_down dialtry
  370.   global linestatus instdir mypicup mypicdown startwarn 
  371.   global modemdevice Ifname Ttydev Pppspeed Localip Remoteip
  372.   set dialtry 0
  373.   if {$pid != 0} {
  374.     catch {killpid} message
  375.   }
  376.   if [catch {exec $ppp_down &} result] {
  377.     error $result
  378.   }
  379.  
  380.   set message [modemclose [file tail $modemdevice]]
  381.  
  382.   set pid 0
  383.   set info_linestatus [catch {exec netstat -nr | grep ppp0} result]
  384.   if {$info_linestatus == 1} {
  385.     set linestatus "LINE down"
  386.     .info.action.ppp.info configure -image $mypicdown
  387.     wm iconbitmap . "@$instdir/pppdownicon"
  388.     set Ifname ""
  389.     set Ttydev ""
  390.     set Pppspeed ""
  391.     set Localip ""
  392.     set Remoteip ""
  393.     startonlinetime
  394.   }
  395. }
  396.  
  397.  
  398. # is there already a ppp-connection?
  399.  
  400. proc pppinfo {} {
  401.   global linestatus instdir mypicup mypicdown startwarn 
  402.   global Ifname Ttydev Pppspeed Localip Remoteip
  403.   set info_linestatus [catch {exec netstat -nr | grep ppp0}]
  404.   if {$info_linestatus == 1} {
  405.     set linestatus "LINE down"
  406.     .info.action.ppp.info configure -image $mypicdown
  407.     wm iconbitmap . "@$instdir/pppdownicon"
  408.     set Ifname ""
  409.     set Ttydev ""
  410.     set Pppspeed ""
  411.     set Localip ""
  412.     set Remoteip ""
  413.   } else {
  414.     set linestatus "LINE up"
  415.     .info.action.ppp.info configure -image $mypicup
  416.     wm iconbitmap . "@$instdir/pppupicon"
  417.   }
  418.   startonlinetime
  419. }   
  420.  
  421. # starting the online-time
  422.  
  423. proc startonlinetime {} {
  424.   global zonemoney moneyfile money linestatus lastonlinetime onlinetime onlinemoneytime
  425.   global startwarn startdelay
  426.   if {$linestatus == "LINE down"} {
  427.     set onlinetime "00:00:00"
  428.     set lastonlinetime "00:00:00"
  429.     savemoney $moneyfile $money 
  430.     set money "0.00"
  431.     set onlinemoneytime 0
  432.    } else {
  433.     set money $zonemoney
  434.     set onlinemoneytime 0
  435.     set startwarn [expr [gettime] -$startdelay]
  436.     after [expr 60000 - (($startdelay - 1) * 1000)] warningguard
  437.     onlinetime [expr [gettime] - $startdelay]
  438.   }
  439. }   
  440.  
  441. # Save the configfile
  442.  
  443. proc savemoney {moneyfile money} {
  444.   if {$money != "0.00"} {
  445.     lappend temp $money
  446.     lappend temp [exec date]
  447.     set Datei [open $moneyfile a+]
  448.     puts $Datei "$temp" 
  449.     close $Datei
  450.   }
  451. }
  452.   
  453. # display of the connection-data, from <send> at <ip>
  454.  
  455. proc showppp {letter ifname ttydev pppspeed localip remoteip} {
  456.   global Iconify linestatus Ifname Ttydev Pppspeed Localip Remoteip
  457.   global startwarn mypicup mypicdown instdir
  458.   if {$letter == "p"} {
  459.     set Ifname $ifname
  460.     set Ttydev $ttydev
  461.     set Pppspeed $pppspeed
  462.     set Localip $localip
  463.     set Remoteip $remoteip
  464.   } else {
  465.     set linestatus "LINE down"
  466.     .info.action.ppp.info configure -image $mypicdown
  467.     wm iconbitmap . "@$instdir/pppdownicon"
  468.     set Ifname ""
  469.     set Ttydev ""
  470.     set Pppspeed ""
  471.     set Localip ""
  472.     set Remoteip ""
  473.     startonlinetime
  474.   }
  475.   if {$Iconify == 1} {
  476.     after 5000 {wm iconify .}
  477.   }
  478. }
  479.  
  480. # clock
  481.  
  482. proc Time {} {
  483.   global realunits Time refreshtime nightstart nightstop zonelength zonedaytime 
  484.   upvar #0 zoneday localzoneday
  485.   set Time [string range [getshowtime] 0 4]
  486.   set realrefresh ""
  487.   getpartzone zonedaytime $nightstart $nightstop $localzoneday(0) $localzoneday(1) $localzoneday(2) $localzoneday(3) $localzoneday(4) $localzoneday(5) $localzoneday(6) 
  488.   set realunits  [expr $zonelength * $zonedaytime]
  489.   after 60000 {Time}
  490. }
  491.  
  492. # warning after some time
  493.  
  494. proc warningguard {} {
  495.   global linestatus startwarn warningtime flagwarning
  496.   if {($flagwarning == 1) && ($linestatus == "LINE up")} {
  497.     if {[expr [gettime] - $startwarn] > [expr $warningtime * 60]} {
  498.       incr startwarn [expr $warningtime * 60] 
  499.       bell
  500.       after 1000 bell
  501.       after 2000 bell
  502.       after 3000 bell
  503.       after 4000 bell
  504.     }
  505.   } 
  506.   if {$linestatus == "LINE up"} {
  507.     after 60000 {warningguard}
  508.   }
  509. }
  510.  
  511. # display of online-time
  512.  
  513. proc onlinetime {starttime} {
  514.   global zonemoney money zonelength zonedaytime onlinetime onlinemoneytime linestatus
  515.   global lastonlinetime progname refreshtime showmoneyinicon
  516.   if {$linestatus == "LINE down"} {
  517.     wm iconname . $progname
  518.     return
  519.   }
  520.   set temp [expr ([onlineshowtime raw $starttime] - $onlinemoneytime) - ($zonelength * $zonedaytime)]
  521.   
  522.   if {$temp > 0} {
  523.     incr onlinemoneytime [expr $zonelength * $zonedaytime]
  524.     set money [format "%3.2f" [expr $money + $zonemoney]]
  525.     set temp [expr $temp - ($zonelength * $zonedaytime)] 
  526.   }
  527.  
  528.   if {$refreshtime < 59} {
  529.     set onlinetime [onlineshowtime showsec $starttime]
  530.     set lastonlinetime [showdifftime showsec $temp]
  531.   } else {
  532.     set onlinetime [onlineshowtime showmin $starttime]
  533.     set lastonlinetime [showdifftime showmin $temp]
  534.   }
  535.  
  536. # still needs too much time !!!
  537.  
  538.   if {$showmoneyinicon == 1} {
  539.     wm iconname . $onlinetime
  540.    } else {
  541.     if {$showmoneyinicon == 0} {
  542.        wm iconname . $progname
  543.        set showmoneyinicon 2
  544.     }
  545.   }
  546.  
  547.   after [expr $refreshtime * 1000] onlinetime $starttime
  548.  
  549. # show the about-text (copyright)
  550.  
  551. proc about {version} {
  552.   global progname
  553.   toplevel .top3 -cursor man
  554.   wm transient .top3 .
  555.   wm title .top3 "about"
  556.   wm geometry .top3 +300+300
  557.   button .top3.exit -text "OK" -command {destroy .top3}
  558.   message .top3.help1 -relief raised -justify left -width 13c -bd 2 -font \
  559.           -b&h-lucida-bold-r-normal-*-25-*-*-*-*-*-*-* \
  560.           -text "$progname $version"
  561.   message .top3.help2 -relief raised -justify left -width 13c -bd 2 -font \
  562.           -Adobe-Helvetica-Medium-R-Normal--*-180-* \
  563.           -text "                               by\n
  564.  Matthias Ott \n Gebrⁿder-Grimm-Weg 9\n 91522 Ansbach \n Germany \n
  565.  E-Mail: msott@cip.informatik.uni-erlangen.de \n\n(c) 1995"
  566.   pack .top3.help1 .top3.help2 -side top
  567.   pack .top3.exit -ipadx 1c -pady 1m -side bottom
  568. }
  569.  
  570. # helptext
  571.  
  572. proc Help {} {
  573.   global instdir 
  574.   set text ""
  575.   toplevel .top4 -cursor man
  576.   wm transient .top4 .
  577.   wm title .top4 "help"
  578.   wm geometry .top4 +400+200
  579.   button .top4.exit -text "OK" -command {destroy .top4}
  580.   message .top4.help -relief raised -justify left -bd 2 -font \
  581.           -*-courier-bold-r-normal-*-12-*-*-*-*-*-*-* 
  582.   if {[catch {open $instdir/startppp-help r} Datei] == 1} {
  583.     tk_dialog .help "Help" "No file $instdir/startppp-help" error 0 ok
  584.     return
  585.   } else {
  586.     while {[gets $Datei line] >=0} {
  587.       set text "$text\n$line"
  588.     }
  589.     close $Datei
  590.   } 
  591.   .top4.help configure -text $text
  592.   pack .top4.help -side top
  593.   pack .top4.exit -ipadx 1c -pady 1m -side bottom
  594.  
  595. }
  596.  
  597. # show the money already spent
  598.  
  599. proc wholemoney {moneyfile currency} {
  600.   global zonemoney
  601.   set wholemoney 0
  602.   if {[catch {open $moneyfile r} Datei] == 1} {
  603.     tk_dialog .money "Money" "No file $moneyfile" error 0 ok
  604.     return
  605.   } else {
  606.     while {[gets $Datei number] >=0} {
  607.       set wholemoney [expr $wholemoney + [lindex $number 0]]
  608.     }
  609.     close $Datei
  610.     set result [expr $wholemoney / $zonemoney]
  611.     tk_dialog .money "Money" "Money spent: [format "%5.2f" $wholemoney] $currency\n\n          Units: [expr int($result)]" info 0 ok
  612.   }
  613. }
  614.  
  615. # Exit startppp
  616.  
  617. proc Exit {moneyfile} {
  618.   global pid message mypicup mypicdown mypicpppup mypicpppdown mypicexit
  619.   global money 
  620.   if {[tk_dialog .exit "Exit?" "Really quit?" questhead 1 yes no] == 0} {
  621.     if {$pid != 0} {
  622.       catch {killpid} message
  623.       set pid 0
  624.     }
  625.     savemoney $moneyfile $money     
  626.     image delete $mypicup
  627.     image delete $mypicdown 
  628.     image delete $mypicpppup
  629.     image delete $mypicpppdown 
  630.     image delete $mypicexit 
  631.     exit
  632.   }
  633. }
  634.  
  635. proc altermodem {} {
  636.  
  637.   toplevel .am 
  638.   wm transient .am .
  639.   wm title .am "config modem"
  640.   wm geometry .am +300+100
  641.   grab .am
  642.   
  643.   frame .am.text 
  644.   label .am.text.label -text "Alter the modemconfigs:"
  645.  
  646.   frame .am.buttons
  647.   frame .am.buttons.z1  
  648.   entry .am.buttons.z1.value -width 20 -textvariable modeminit
  649.   label .am.buttons.z1.entry -cursor question_arrow -text " Initstring  "
  650.  
  651.   frame .am.buttons.z2  
  652.   entry .am.buttons.z2.value -width 20 -textvariable modemnumber
  653.   label .am.buttons.z2.entry -cursor question_arrow -text " Number"
  654.  
  655.   frame .am.buttons.z3  
  656.   radiobutton .am.buttons.z3.button -cursor question_arrow -text "Tone" -variable dialtype -value T
  657.  
  658.   frame .am.buttons.z4  
  659.   radiobutton .am.buttons.z4.button -cursor question_arrow -text "Pulse" -variable dialtype -value P
  660.  
  661.   frame .am.buttons.z5  
  662.   entry .am.buttons.z5.value -width 20 -textvariable modemdevice
  663.   label .am.buttons.z5.entry -cursor question_arrow -text " Modem"
  664.  
  665.   frame .am.buttons.z6  
  666.   scale .am.buttons.z6.scale -length 9c -relief ridge -label " Delay of dialrepeat (sec)" -from 0 -to 60 -orient horizontal -variable repeatdelay
  667.  
  668.   frame .am.buttons.z7
  669.   label .am.buttons.z7.entry -cursor question_arrow -text " Linespeed"
  670.   radiobutton .am.buttons.z7.button1 -cursor question_arrow -text "38400" -variable modemspeed -value 38400
  671.   radiobutton .am.buttons.z7.button2 -cursor question_arrow -text "19200" -variable modemspeed -value 19200
  672.   radiobutton .am.buttons.z7.button3 -cursor question_arrow -text "9600" -variable modemspeed -value 9600
  673.   radiobutton .am.buttons.z7.button4 -cursor question_arrow -text "1200" -variable modemspeed -value 1200
  674.  
  675.   frame .am.buttons.z8
  676.   label .am.buttons.z8.entry -cursor question_arrow -text " Parity"
  677.   radiobutton .am.buttons.z8.button1 -cursor question_arrow -text "None" -variable modemparity -value CS8
  678.   radiobutton .am.buttons.z8.button2 -cursor question_arrow -text "Even" -variable modemparity -value CS7|PARENB
  679.   radiobutton .am.buttons.z8.button3 -cursor question_arrow -text "Odd" -variable modemparity -value CS7|PARENB|PARODD
  680.  
  681.   frame .am.buttons.z9
  682.   label .am.buttons.z9.entry -cursor question_arrow -text " Stop bits"
  683.   radiobutton .am.buttons.z9.button1 -cursor question_arrow -text "One" -variable modemstopbits -value |
  684.   radiobutton .am.buttons.z9.button2 -cursor question_arrow -text "Two" -variable modemstopbits -value CSTOPB
  685.  
  686.   frame .am.buttons.z10  
  687.   scale .am.buttons.z10.scale -length 9c -relief ridge -label " timeout for expect (sec)" -from 0 -to 200 -orient horizontal -variable modemtimeout
  688.  
  689.   frame .am.options 
  690.   button .am.options.ok -cursor target -text Ok -command {destroy .am}
  691.   button .am.options.save -cursor target -text Save -command {saveconfigfile}
  692.  
  693.  
  694.   pack .am.text -side top
  695.   pack .am.text.label -side left
  696.   pack .am.buttons -pady 5
  697.   pack .am.buttons.z5 .am.buttons.z1 .am.buttons.z2 .am.buttons.z3 .am.buttons.z4 .am.buttons.z6 -side top -fill x
  698.   pack .am.buttons.z7 .am.buttons.z8 .am.buttons.z9 .am.buttons.z10 -side top -fill x
  699.   pack .am.buttons.z1.entry -side left
  700.   pack .am.buttons.z1.value -side right -padx 10
  701.   pack .am.buttons.z2.entry -side left
  702.   pack .am.buttons.z2.value -side right -padx 10
  703.   pack .am.buttons.z3.button -side left 
  704.   pack .am.buttons.z4.button -side left 
  705.   pack .am.buttons.z5.entry -side left
  706.   pack .am.buttons.z5.value -side right -padx 10
  707.   pack .am.buttons.z6.scale -side left
  708.   pack .am.buttons.z7.entry -side top
  709.   pack .am.buttons.z7.button1 -side left
  710.   pack .am.buttons.z7.button2 -side left
  711.   pack .am.buttons.z7.button3 -side left
  712.   pack .am.buttons.z7.button4 -side left
  713.   pack .am.buttons.z8.entry -side top
  714.   pack .am.buttons.z8.button1 -side left
  715.   pack .am.buttons.z8.button2 -side left
  716.   pack .am.buttons.z8.button3 -side left
  717.   pack .am.buttons.z9.entry -side top
  718.   pack .am.buttons.z9.button1 -side left
  719.   pack .am.buttons.z9.button2 -side left
  720.   pack .am.buttons.z10.scale -side left
  721.  
  722.   pack .am.options -side top -fill x -pady 5
  723.   pack .am.options.ok -side right -padx 5
  724.   pack .am.options.save -side left -padx 5
  725.  
  726.   tkwait window .am
  727.  
  728. }
  729.  
  730.  
  731.  
  732.  
  733. # change the configfile
  734.  
  735. proc alterunits {} {
  736.   global realunits flagwarning nightstart nightstop zonelength refreshtime zonedaytime button
  737.  
  738.   toplevel .au 
  739.   wm transient .au .
  740.   wm title .au "config"
  741.   wm geometry .au +300+100
  742.   grab .au
  743.   
  744.   frame .au.text 
  745.   label .au.text.label -text "Alter the configs:"
  746.  
  747.   frame .au.buttons
  748.  
  749.   frame .au.buttons.z1
  750.   entry .au.buttons.z1.value -width 10 -textvariable zone(1)
  751.   radiobutton .au.buttons.z1.button -cursor question_arrow -text "Zone 1" -variable button -value 1
  752.  
  753.   frame .au.buttons.z2
  754.   entry .au.buttons.z2.value -width 10 -textvariable zone(2)
  755.   radiobutton .au.buttons.z2.button -cursor question_arrow -text "Zone 2" -variable button -value 2
  756.  
  757.   frame .au.buttons.z3 
  758.   entry .au.buttons.z3.value -width 10 -textvariable zone(3)
  759.   radiobutton .au.buttons.z3.button -cursor question_arrow -text "Zone 3" -variable button -value 3
  760.  
  761.   frame .au.buttons.z4  
  762.   entry .au.buttons.z4.value -width 10 -textvariable zonemoney
  763.   label .au.buttons.z4.entry -cursor question_arrow -text " Length of one unit"
  764.  
  765.   frame .au.buttons.z5 
  766.   entry .au.buttons.z5.value -width 10 -textvariable currency
  767.   label .au.buttons.z5.entry -cursor question_arrow -text " Your currency"
  768.  
  769.   frame .au.buttons.z6 
  770.   checkbutton .au.buttons.z6.button -cursor question_arrow -text "Iconify after connect" -variable Iconify
  771.  
  772.   frame .au.buttons.z16 
  773.   checkbutton .au.buttons.z16.button -cursor question_arrow -text "Show terminal" -variable showterminal
  774.  
  775.   frame .au.buttons.z7 
  776.   checkbutton .au.buttons.z7.button -cursor question_arrow -text "Show Onlinetime in Icon" -variable showmoneyinicon
  777.  
  778.   frame .au.buttons.z8 
  779.   entry .au.buttons.z8.value -width 10 -textvariable ppp_up
  780.   label .au.buttons.z8.entry -cursor question_arrow -text " PPP-Up"
  781.  
  782.   frame .au.buttons.z9 
  783.   entry .au.buttons.z9.value -width 10 -textvariable ppp_down
  784.   label .au.buttons.z9.entry -cursor question_arrow -text " PPP-Down"
  785.  
  786.   frame .au.buttons.z17 
  787.   entry .au.buttons.z17.value -width 10 -textvariable startdelay
  788.   label .au.buttons.z17.entry -cursor question_arrow -text " Delay after CONNECT (sec)"
  789.  
  790.   frame .au.buttons.z10  
  791.   scale .au.buttons.z10.scale -length 13c -relief ridge -label " Refresh of time" -from 1 -to 60 -orient horizontal -variable refreshtime
  792.  
  793.   frame .au.buttons.z11  
  794.   scale .au.buttons.z11.scale -length 13c -relief ridge -label " Begin of nightzone" -from 1 -to 24 -orient horizontal -variable nightstart 
  795.  
  796.   frame .au.buttons.z12 
  797.   scale .au.buttons.z12.scale -length 13c -relief ridge -label " End of nightzone" -from 1 -to 24 -orient horizontal -variable nightstop 
  798.  
  799.   frame .au.buttons.z13 
  800.   checkbutton .au.buttons.z13.button -cursor question_arrow -text "Warning (in minutes)" -variable flagwarning -command {configwarning $flagwarning}
  801.   scale .au.buttons.z13.scale -length 13c -relief ridge -from 1 -to 120 -orient horizontal -variable warningtime
  802.   
  803.   frame .au.buttons.z14 
  804.   checkbutton .au.buttons.z14.button0 -cursor question_arrow -text "Son" -variable zoneday(0)
  805.   checkbutton .au.buttons.z14.button1 -cursor question_arrow -text "Mon" -variable zoneday(1)
  806.   checkbutton .au.buttons.z14.button2 -cursor question_arrow -text "Tue" -variable zoneday(2)
  807.   checkbutton .au.buttons.z14.button3 -cursor question_arrow -text "Wed" -variable zoneday(3)
  808.   checkbutton .au.buttons.z14.button4 -cursor question_arrow -text "Thu" -variable zoneday(4)
  809.   checkbutton .au.buttons.z14.button5 -cursor question_arrow -text "Fri" -variable zoneday(5)
  810.   checkbutton .au.buttons.z14.button6 -cursor question_arrow -text "Sat" -variable zoneday(6)
  811.  
  812.   label .au.buttons.z15 -cursor question_arrow -text " Days with wholeday-nightzone"
  813.  
  814.   frame .au.options 
  815.   button .au.options.ok -cursor target -text Ok -command {set zonelength $zone($button)
  816.     set realunits  [expr $zonelength * $zonedaytime]
  817.     destroy .au
  818.   }
  819.   button .au.options.save -cursor target -text Save -command {saveconfigfile}
  820.  
  821.  
  822.  
  823.   pack .au.text -side top
  824.   pack .au.text.label -side left
  825.   pack .au.buttons -pady 5
  826.   pack .au.buttons.z8 .au.buttons.z9 .au.buttons.z17 .au.buttons.z1 .au.buttons.z2 .au.buttons.z3 .au.buttons.z4 -side top -fill x
  827.   pack .au.buttons.z5 .au.buttons.z10 .au.buttons.z11 .au.buttons.z12 -fill x -side top
  828.   pack .au.buttons.z15 -side top -anchor w
  829.   pack .au.buttons.z14 .au.buttons.z13 -fill x -side top
  830.   pack .au.buttons.z6 .au.buttons.z16 .au.buttons.z7 -fill x -side top
  831.   pack .au.buttons.z1.button -side left 
  832.   pack .au.buttons.z1.value -side right -padx 10
  833.   pack .au.buttons.z2.button -side left
  834.   pack .au.buttons.z2.value -side right -padx 10
  835.   pack .au.buttons.z3.button -side left
  836.   pack .au.buttons.z3.value -side right -padx 10
  837.   pack .au.buttons.z4.entry -side left
  838.   pack .au.buttons.z4.value -side right -padx 10
  839.   pack .au.buttons.z5.entry -side left
  840.   pack .au.buttons.z5.value -side right -padx 10
  841.   pack .au.buttons.z6.button -side left
  842.   pack .au.buttons.z7.button -side left
  843.   pack .au.buttons.z8.entry -side left 
  844.   pack .au.buttons.z8.value -side right -padx 10
  845.   pack .au.buttons.z9.entry -side left 
  846.   pack .au.buttons.z9.value -side right -padx 10
  847.   pack .au.buttons.z17.entry -side left 
  848.   pack .au.buttons.z17.value -side right -padx 10
  849.   pack .au.buttons.z10.scale -pady 3 -side left 
  850.   pack .au.buttons.z11.scale -pady 3 -side left
  851.   pack .au.buttons.z12.scale -pady 3 -side left
  852.   pack .au.buttons.z13.button -side top -anchor w
  853.   pack .au.buttons.z13.scale -side top -side left
  854.   pack .au.buttons.z14.button0 -side left
  855.   pack .au.buttons.z14.button1 -side left
  856.   pack .au.buttons.z14.button2 -side left
  857.   pack .au.buttons.z14.button3 -side left
  858.   pack .au.buttons.z14.button4 -side left
  859.   pack .au.buttons.z14.button5 -side left
  860.   pack .au.buttons.z14.button6 -side left
  861.   pack .au.buttons.z16.button -side left
  862.   
  863.   pack .au.options -side top -fill x -pady 5
  864.   pack .au.options.ok -side right -padx 5
  865.   pack .au.options.save -side left -padx 5
  866.  
  867.   configwarning $flagwarning
  868.   tkwait window .au
  869.  
  870. }
  871.  
  872. # dis/enable warningscale
  873.  
  874. proc configwarning flagwarning {
  875.   if {$flagwarning == 0} {
  876.     .au.buttons.z13.scale configure -state disabled -troughcolor grey
  877.   } else {
  878.     .au.buttons.z13.scale configure -state normal -troughcolor [option get .au.buttons.z10.scale activeBackground Foreground]
  879.   }
  880.  
  881. # show the realunits
  882.  
  883. proc realunits {} {
  884.   global nightstart nightstop zonelength zonedaytime 
  885.   upvar #0 zoneday localzoneday
  886.   getpartzone zonedaytime $nightstart $nightstop $localzoneday(0) $localzoneday(1) $localzoneday(2) $localzoneday(3) $localzoneday(4) $localzoneday(5) $localzoneday(6) 
  887.   tk_dialog .realunits "The real units" "Zonelength: [expr $zonelength * $zonedaytime]" info 0 ok
  888. }
  889.    
  890. # save the configfile (I/O)
  891.  
  892. proc saveconfigfile {} {
  893.   global configfile
  894.   global button refreshtime ppp_up ppp_down instdir zonemoney currency showmoneyinicon Iconify
  895.   global modeminit dialtype modemnumber startdelay nightstart nightstop flagwarning warningtime
  896.   global showterminal modemtimeout modemspeed modemparity modemstopbits modemdevice repeatdelay
  897.   upvar #0 zone localzone
  898.   upvar #0 zoneday localzoneday
  899.   set Datei [open $configfile w+]
  900.   puts $Datei $instdir
  901.   puts $Datei $localzone(1)
  902.   puts $Datei $localzone(2)
  903.   puts $Datei $localzone(3)
  904.   puts $Datei $zonemoney
  905.   puts $Datei $currency
  906.   puts $Datei $showmoneyinicon
  907.   puts $Datei $Iconify
  908.   puts $Datei $ppp_up
  909.   puts $Datei $ppp_down
  910.   puts $Datei $refreshtime
  911.   puts $Datei $button
  912.   puts $Datei $nightstart
  913.   puts $Datei $nightstop
  914.   puts $Datei $flagwarning
  915.   puts $Datei $warningtime
  916.   puts $Datei $localzoneday(0)
  917.   puts $Datei $localzoneday(1)
  918.   puts $Datei $localzoneday(2)
  919.   puts $Datei $localzoneday(3)
  920.   puts $Datei $localzoneday(4)
  921.   puts $Datei $localzoneday(5)
  922.   puts $Datei $localzoneday(6)
  923.   puts $Datei $startdelay
  924.   puts $Datei $modeminit
  925.   puts $Datei $modemnumber
  926.   puts $Datei $dialtype
  927.   puts $Datei $modemdevice
  928.   puts $Datei $repeatdelay
  929.   puts $Datei $modemspeed
  930.   puts $Datei $modemparity
  931.   puts $Datei $modemstopbits
  932.   puts $Datei $modemtimeout
  933.   puts $Datei $showterminal
  934.   close $Datei
  935. }
  936.   
  937. # move goodiepicture (enter)
  938.  
  939. proc goodieenter {} {
  940.   global linestatus mypicdown2 mypicup2
  941.   if {$linestatus == "LINE up"} {
  942.     .info.action.ppp.info configure -image $mypicup2
  943.   } else {
  944.     .info.action.ppp.info configure -image $mypicdown2
  945.   }
  946. }
  947.  
  948. # move goodiepicture (leave)
  949.  
  950. proc goodieleave {} {
  951.   global linestatus mypicdown mypicup
  952.   if {$linestatus == "LINE up"} {
  953.     .info.action.ppp.info configure -image $mypicup
  954.   } else {
  955.     .info.action.ppp.info configure -image $mypicdown
  956.   }
  957. }
  958.  
  959. proc showterminal {} {
  960.  
  961.   set result [catch {toplevel .sm}]
  962.   if {$result == 1} return 
  963.   wm title .sm "terminal"
  964.   wm geometry .sm +300+100
  965.   wm focusmodel .sm active
  966.   frame .sm.input
  967.   text .sm.input.text -relief raised -bd 2 -xscrollcommand ".sm.input.scroll2 set" -yscrollcommand ".sm.input.scroll1 set"
  968.   scrollbar .sm.input.scroll1 -command ".sm.input.text yview"
  969.   scrollbar .sm.input.scroll2 -orient horizontal -command ".sm.input.text xview"
  970.   button .sm.exit -text "Exit" -command {destroy .sm}
  971.   
  972.   pack .sm.input -side top
  973.   pack .sm.input.scroll2 -side bottom -fill x
  974.   pack .sm.input.scroll1 -side right -fill y
  975.   pack .sm.input.text -side left
  976.   pack .sm.exit -ipadx 1c -pady 1m -side bottom
  977.  
  978. }
  979.  
  980. proc changestate {} {
  981.   global linestatus
  982.   set result [tk_dialog .state "Change state" "Change the state of the line" questhead 2 up down cancel]
  983.   if {$result == 0} {
  984.     set linestatus "LINE up"
  985.     startonlinetime
  986.   }
  987.   if {$result == 1} {
  988.     down
  989.   }
  990. }
  991.     
  992.   
  993.  
  994. # Main-Program
  995.  
  996. pppinfo
  997. Time
  998. if {$commandoption == "-start"} {
  999.   up
  1000. }
  1001. if {$commandoption == "-close"} {
  1002.   down
  1003. }
  1004. # set linestatus "LINE up"
  1005. # startonlinetime
  1006.